package cn.meibang.common.beauty.provider.dao;

import cn.apestar.core.database.BaseMapper;
import cn.meibang.common.beauty.provider.domain.BeautyConsultationOrderUserLatest;
import cn.meibang.common.beauty.provider.request.ListOrderUserRequest;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface BeautyConsultationOrderUserLatestMapper extends BaseMapper {

    @Delete({"delete from beauty_consultation_order_user_latest", "where id = #{id,jdbcType=BIGINT}"})
    int deleteByPrimaryKey(Long id);

    @Delete({"delete from beauty_consultation_order_user_latest", "where create_by = #{createBy,jdbcType=BIGINT} and order_type = #{orderType}"})
    int delete(@Param("createBy") Long createBy, @Param("orderType") String orderType);

    @Delete({"delete from beauty_consultation_order_user_latest", "where openid = #{openid,jdbcType=VARCHAR} and order_type = #{orderType}"})
    int deleteByOpenidAndOrderType(@Param("openid") String openid, @Param("orderType") String orderType);

    @Insert({"insert into beauty_consultation_order_user_latest (id, tag, user_id, openid, ", "store_id, consultant_id, title, ", "order_id, order_type, ",
            "create_by, create_date)", "values (#{id,jdbcType=BIGINT}, #{tag,jdbcType=VARCHAR}, #{userId}, #{openid}, #{storeId}, ",
            "#{consultantId,jdbcType=BIGINT}, #{title,jdbcType=VARCHAR}, ", "#{orderId,jdbcType=BIGINT}, #{orderType,jdbcType=VARCHAR}, ",
            "#{createBy,jdbcType=BIGINT}, #{createDate,jdbcType=TIMESTAMP})"})
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(BeautyConsultationOrderUserLatest record);

    @InsertProvider(type = BeautyConsultationOrderUserLatestSqlProvider.class, method = "insertSelective")
    int insertSelective(BeautyConsultationOrderUserLatest record);

    @Select({"select", "id, tag, user_id, openid, store_id, consultant_id, title, order_id, order_type, create_by, create_date", "from beauty_consultation_order_user_latest",
            "where id = #{id,jdbcType=BIGINT}"})
    @Results({@Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "tag", property = "tag", jdbcType = JdbcType.VARCHAR),
            @Result(column = "user_id", property = "userId", jdbcType = JdbcType.BIGINT),
            @Result(column = "openid", property = "openid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "store_id", property = "storeId", jdbcType = JdbcType.BIGINT),
            @Result(column = "consultant_id", property = "consultantId", jdbcType = JdbcType.BIGINT),
            @Result(column = "title", property = "title", jdbcType = JdbcType.VARCHAR),
            @Result(column = "order_id", property = "orderId", jdbcType = JdbcType.BIGINT),
            @Result(column = "order_type", property = "orderType", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_by", property = "createBy", jdbcType = JdbcType.BIGINT),
            @Result(column = "create_date", property = "createDate", jdbcType = JdbcType.TIMESTAMP)})
    BeautyConsultationOrderUserLatest selectByPrimaryKey(Long id);


    @SelectProvider(type = BeautyConsultationOrderUserLatestSqlProvider.class, method = "select")
    @Results({@Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "tag", property = "tag", jdbcType = JdbcType.VARCHAR),
            @Result(column = "user_id", property = "userId", jdbcType = JdbcType.BIGINT),
            @Result(column = "openid", property = "openid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "store_id", property = "storeId", jdbcType = JdbcType.BIGINT),
            @Result(column = "consultant_id", property = "consultantId", jdbcType = JdbcType.BIGINT),
            @Result(column = "title", property = "title", jdbcType = JdbcType.VARCHAR),
            @Result(column = "order_id", property = "orderId", jdbcType = JdbcType.BIGINT),
            @Result(column = "order_type", property = "orderType", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_by", property = "createBy", jdbcType = JdbcType.BIGINT),
            @Result(column = "create_date", property = "createDate", jdbcType = JdbcType.TIMESTAMP)})
    List<BeautyConsultationOrderUserLatest> select(@Param("userId") Long userId,
                                                   @Param("openid") String openid);

    @SelectProvider(type = BeautyConsultationOrderUserLatestSqlProvider.class, method = "selectByListRequest")
    @Results({@Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "tag", property = "tag", jdbcType = JdbcType.VARCHAR),
            @Result(column = "user_id", property = "userId", jdbcType = JdbcType.BIGINT),
            @Result(column = "openid", property = "openid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "store_id", property = "storeId", jdbcType = JdbcType.BIGINT),
            @Result(column = "consultant_id", property = "consultantId", jdbcType = JdbcType.BIGINT),
            @Result(column = "title", property = "title", jdbcType = JdbcType.VARCHAR),
            @Result(column = "order_id", property = "orderId", jdbcType = JdbcType.BIGINT),
            @Result(column = "order_type", property = "orderType", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_by", property = "createBy", jdbcType = JdbcType.BIGINT),
            @Result(column = "create_date", property = "createDate", jdbcType = JdbcType.TIMESTAMP)})
    List<BeautyConsultationOrderUserLatest> selectByListRequest(ListOrderUserRequest request);

    @UpdateProvider(type = BeautyConsultationOrderUserLatestSqlProvider.class, method = "updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(BeautyConsultationOrderUserLatest record);

    @Update({"update beauty_consultation_order_user_latest", "set tag = #{tag,jdbcType=VARCHAR},",
            "store_id = #{storeId},",
            "user_id = #{userId},",
            "openid = #{openid},",
            "consultant_id = #{consultantId,jdbcType=BIGINT},", "title = #{title,jdbcType=VARCHAR},", "order_id = #{orderId,jdbcType=BIGINT},",
            "order_type = #{orderType,jdbcType=VARCHAR},", "create_by = #{createBy,jdbcType=BIGINT},",
            "create_date = #{createDate,jdbcType=TIMESTAMP}", "where id = #{id,jdbcType=BIGINT}"})
    int updateByPrimaryKey(BeautyConsultationOrderUserLatest record);
}